package com.yangyang.textscope;

import android.content.Context;
import android.content.ClipboardManager;
import android.content.ClipData;
import androidx.core.content.ContextCompat;

public class ClipboardHelper {
    public static boolean canReadClipboard(Context context) {
        // Android 10+ 默认允许读取剪切板，无需权限检查
        return true;
    }

    public static String getClipboardText(Context context) {
        ClipboardManager clipboard = ContextCompat.getSystemService(context, ClipboardManager.class);
        if (clipboard != null && clipboard.hasPrimaryClip()) {
            ClipData clip = clipboard.getPrimaryClip();
            if (clip != null && clip.getItemCount() > 0) {
                return clip.getItemAt(0).getText().toString();
            }
        }
        return null;
    }

    public static void setClipboardText(Context context, String text) {
        ClipboardManager clipboard = ContextCompat.getSystemService(context, ClipboardManager.class);
        if (clipboard != null) {
            ClipData clip = ClipData.newPlainText("label", text);
            clipboard.setPrimaryClip(clip);
        }
    }
}